package com.eliota.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author M.G
 * @create 2023-03-21 0:44
 * @date 2023/3/21 0:44
 *
 * http://localhost:端口swagger-ui.html
 * http://localhost:端口/doc.html
 *
 */

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后端接口")
                .apiInfo(apiInfo("Springboot项目Api接口","1.0"))
                .useDefaultResponseMessages(true)
                .forCodeGeneration(false)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(String title,String version){
        return new ApiInfoBuilder()
                .title(title)
                .description("Springboot项目Swagger显示界面")
                .termsOfServiceUrl("http://localhost:9091")
                .contact(new Contact("Eliota","域名:......","eliota@test.com"))
                .version(version)
                .build();
    }
}
